package cn.tedu.smartos.health.controller;

import cn.tedu.smartos.base.response.JsonResult;
import cn.tedu.smartos.health.pojo.dto.DeviceAddParam;
import cn.tedu.smartos.health.pojo.vo.DeviceVO;
import cn.tedu.smartos.health.service.DeviceService;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "05.设备模块")
@Slf4j
@RestController
@RequestMapping("/api/v1/device/")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    @ApiOperation("添加设备(绑定)")
    @ApiOperationSupport(order = 10)
    @PostMapping("addDevice")
    public JsonResult addDevice(@RequestBody DeviceAddParam deviceAddParam){
        log.debug("开始处理【添加设备】的请求,参数{}",deviceAddParam);
        deviceService.addDevice(deviceAddParam);
        return JsonResult.ok();
    }
    @ApiOperation("移除设备(解绑)")
    @ApiOperationSupport(order = 20)
    @PostMapping("removeDevice")
    public JsonResult removeDevice(Long deviceId){
        log.debug("开始处理【移除设备】的请求,参数{}",deviceId);
        deviceService.removeDevice(deviceId);
        return JsonResult.ok();
    }
    @ApiOperation("查询设备列表")
    @ApiOperationSupport(order = 30)
    @GetMapping("list")
    public JsonResult list(@RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "10") Integer pageSize){
        log.debug("开始处理【查询设备列表】的请求,参数{},{}",pageNum,pageSize);
        PageInfo<DeviceVO> list = deviceService.list(pageNum,pageSize);
        return JsonResult.ok(list);
    }
    @ApiOperation("查看设备详情")
    @ApiOperationSupport(order = 40)
    @GetMapping("detail")
    public JsonResult detail(Long deviceId){
        log.debug("开始处理【查看设备详情】的请求,参数{}",deviceId);
        DeviceVO deviceVO = deviceService.detail(deviceId);
        return JsonResult.ok(deviceVO);
    }
}
